#
#	Makefile for C languages
#

CC = gcc
CFLAGS = -Wall -ggdb
LDFLAGS = -lpthread -ldl -lz
#SSL_PATH = /home/data/source/network/openssl-0.9.8o
SSL_PATH = /home/data/source/network/openssl-1.0.1g
SSL_LIBS = $(SSL_PATH)/libssl.a $(SSL_PATH)/libcrypto.a

ifneq (".deps", "$(wildcard .deps)")
	DEPS = .deps
endif

TARGET = ssl_client ssl_server

.PHONY : all test clean depclean

# for all target
all : $(TARGET)

ssl_client : ip_addr.o sock_util.o ssl_util.o ssl_client.o $(SSL_LIBS)
	$(CC) -o $@ $^ $(LDFLAGS)


ssl_server : ip_addr.o sock_util.o ssl_util.o ssl_server.o $(SSL_LIBS)
	$(CC) -o $@ $^ $(LDFLAGS)

# for test target
test : $(TEST)

# for clean target
clean :
	rm -f *.o $(TARGET) $(TEST)


# for depclean target
depclean:
	rm -rf *.o $(TARGET) $(TEST) .deps


%.o : %.c $(DEPS)
	$(CC) $(CFLAGS) -c -o $@ $< -MD -MF .deps/$(<:.c=.d)

$(DEPS) :
	@mkdir -p .deps


-include .deps/*.d


